/*
 * author      : dormi330
 * date        : 2018/7/16
 * description : TODO
 */

package com.deep.trade.adaptor.required.mq.nats;

import com.deep.trade.adaptor.required.mq.MsgSender;
import com.deep.trade.common.BaseMssage;
import io.nats.client.Connection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class NatsMsgSender implements MsgSender {

    @Autowired
    private Connection natsConnection;

    public void sendMsg(String topic, BaseMssage msg) throws IOException {
        // BaseMssage msg = BaseMssage.fromObject(msg);
        String msgStr = msg.uglyString();
        natsConnection.publish(topic, msgStr.getBytes("UTF-8"));
    }
}
